<%@ page import="Service.Crudservice" %>
<%@ page import="Model.student" %>
<%@ page import="java.util.ArrayList" %>
<%--
  Created by IntelliJ IDEA.
  User: whb
  Date: 2024/5/16
  Time: 17:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>分页查询</title>
</head>
<link href="/css/Pageselect.css">
<%
    Crudservice crudservice = new Crudservice();
    ArrayList<student> student = crudservice.student();
    //当前页码
    int nowpage;
    if (request.getParameter("page") == null) {
        nowpage = 1;//翻页时会修改++
    } else {
        nowpage = Integer.valueOf(request.getParameter("page"));
    }
    //每一页的数据量
    int page1 = 3;
//    获取总长度
    int size = student.size();
    //总页数
    int total = size % page1 == 0 ? size / page1 : size / page1 + 1;
    //4. 计算每一页的起始偏移值
    int start = (nowpage - 1) * page1;
    ArrayList<student> pageselect = crudservice.pageselect(start, page1);
%>

<body style='background:pink'>
<table cellpadding=5 cellspacing=3 border=1 width=900 height=550 align=center>
    <tr>
        <th>学号
        </th>
        <th>姓名
        </th>
        <th>年龄
        </th>
        <th>身高
        </th>
        <th>学校
        </th>
        <th>
            操作1
        </th>
        <th>
            操作2
        </th>
    </tr>
    <%
        for (int i = 0; i < pageselect.size(); i++) {
    %>
    <tr>
        <td>
            <%= pageselect.get(i).getId()%>
        </td>
        <td>
            <%= pageselect.get(i).getName()%>
        </td>
        <td>
            <%= pageselect.get(i).getAge()%>
        </td>
        <td>
            <%= pageselect.get(i).getHeight()%>
        </td>
        <td>
            <%= pageselect.get(i).getSchool()%>
        </td>
        <td>
            <a onclick='if(confirm("确定删除吗")) return true;return false;'
               href=crud?type=del&id=<%=pageselect.get(i).getId()%>>删除</a>
        </td>
        <td>
            <a href=one?id=<%=pageselect.get(i).getId()%>>更新</a>
        </td>
    </tr>
    <%
        }
    %>
</table>
<a href='add.jsp'>添加</a>
<a href='out'>退出</a>
<%
    if (nowpage == 1) {
%>
<a class="link">首页</a>
<a class="link">上一页</a>
<a href="Pageselect.jsp?page=<%=nowpage+1%>">下一页</a>
<a href="Pageselect.jsp?page=<%=total%>">尾页</a>
<%
} else if (nowpage == total) {
%>
<a href="Pageselect.jsp?page=1">首页</a>
<a href="Pageselect.jsp?page=<%=nowpage-1%>">上一页</a>
<a class="link">下一页</a>
<a class="link">尾页</a>
<%
} else {
%>
<a href="Pageselect.jsp?page=1">首页</a>
<a href="Pageselect.jsp?page=<%=nowpage-1%>">上一页</a>
<a href="Pageselect.jsp?page=<%=nowpage+1%>">下一页</a>
<a href="Pageselect.jsp?page=<%=total%>">尾页</a>
<%
    }
%>
</body>
</html>

